package srzy.data

import srzy.common.Config
import java.io.File
import srzy.common.CaseFileParser
import srzy.common.Common
import srzy.dao.DBOracle

object PublicData extends srzy.common.Logging {
  var dbCompInfos = Map[String, List[srzy.data.DBCompareInfo]]()
  if (Config.getValue("root", "config", "DBCompareFlag").toBoolean == true)
    dbCompInfos = DBOracle.getCaseInfo

  logger.debug("dbCompInfos prepared")
  val fileName = Config.getValue("root", "config", "CaseNameFile")
  val caseInfos0 = if (fileName == "") {
    DBOracle.getCaseInfo2.map(_._1)
  } else {
    Common.readFromFile(Config.getValue("root", "config", "CaseNameFile"))
  }
  val caseInfos = caseInfos0
    .filter(x => if (x == "") false else true).map(path => {
      logger.debug("start read file :" + path)
      val f = new File(path)
      if (!f.isFile())
        throw new Exception("file:" + path + " is not a file")
      val c = CaseFileParser.parse(Common.readFromFile(path).mkString("\n"))
      c.casePath = path
      c
    }).map(((ci: srzy.data.CaseInfo) => {
      for (i <- dbCompInfos if ci.caseName == i._1) {
        ci.dbCompareInfo = i._2
      }
      ci
    }))

}